package com.gupao.javavip.gof.prototype;

import lombok.Data;

import java.io.*;
import java.util.List;

@Data
public class Article implements Cloneable, Serializable {
    private String id;
    private String time;
    private String title;
    private String content;
    private String type;
    private User user;
    private String readTime;

    private List<Comment> comments;


    @Override
    protected Article clone() {
        return deepClone();
    }

    public Article deepClone() {
        try {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);
            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);

            Article copy = (Article) ois.readObject();
            return copy;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
